#coding=utf-8
'''
Created on 2013年8月29日

@author: xuben
'''

import GameConfig
import cookielib
import urllib2

cookiejar = cookielib.CookieJar()
urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))

#向服务器发送http请求
def send(url, method='get', data=None):
    global urlOpener
    
    req = urllib2.Request(url, data)
    #伪装成谷歌浏览器
    req.add_header("User-Agent", GameConfig.chrome_user_agent)
    #如果是post请求
    if method == 'post':
        req.get_method = lambda:'POST'
    try:
        response = urlOpener.open(req)
    except urllib2.HTTPError, err:
        print err
    result = response.read()
    return result
